#include<iostream>
#include<string>
using namespace std;
int f[11];
int n;
string s;
int main()
{
	cin >> n;
	int ma = 0;
	for (int i = 0; i < n; i++) {
		cin >> s;
		int h = s[0] - '0';
		int t = s[s.size() - 1] - '0';
		f[t] = max(f[t], f[h] + 1);
		ma = max(ma, f[t]);
	}
	cout << n - ma << endl;
	return 0;
}